﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex3.FractionNumber
{
    class FractionNumber : IFormattable
    {
        public int Numerator { get; set; }
        public int Denominator { get; set; }

        public FractionNumber(int numerator, int denominator)
        {
            this.Numerator = numerator;
            this.Denominator = denominator;
        }

        public string ToString(string currencyFormat, IFormatProvider formatProvider)
        {
            if (currencyFormat == "N")
            {
                return String.Format("{0}/{1}",this.Numerator,this.Denominator);
            }
            else if (currencyFormat == "R")
            {
                double realValue = (double)this.Numerator / this.Denominator;
                return string.Format("{0}", realValue);
            }
            else
            {
                throw new FormatException(String.Format("Invalid format: {0}", currencyFormat));
            }
        }

    }
    class FractionNumberTest
    {
        static void Main(string[] args)
        {
            FractionNumber someFractionNumber = new FractionNumber(1, 3);

            Console.WriteLine(string.Format("{0:N}",someFractionNumber));
        }
    }
}
